package it.heima.xmy.Demo1;

import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

/*需求：
1.利用键盘录入，输入一个字符串,统计该字符串中各个字符的数量
2.如用户输入字符串:"helloworld java",程序输出结果：h(1)e(1)l(3)o(2) (2)w(1)r(1)d(1)j(1)a(2)v(1)
3.注：输出结果不要求顺序一致
答案：*/
public class HelloWorldPlusDemo06 {
    static Scanner scanner = new Scanner(System.in);

    public static void main(String[] args) {
        System.out.println("请输入任意长度的字符串：");
        String inPut = scanner.next();
        char[] chars = inPut.toCharArray();
        Map<Character,Integer> map  =new HashMap<>();
        for (int i = 0; i < chars.length; i++) {
            if (map.containsKey(chars[i])){
                Integer integer = map.get(chars[i]);
                integer++;
                map.put(chars[i],integer);
            }else {
                map.put(chars[i],1);
            }
        }
        System.out.println(map);
    }
}
